<?php
/**
 * @资源类
 * 1、投资成本
 * 2、资源图
 * @作者
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;

use app\model\ResourceInvestCostModel;
use app\model\ResourceMapModel;
use app\model\Role;

class Resource extends HomeBase
{
	
	
	public function __construct(){
		
		parent::__construct();
		
		
	}
	public function GetInvestCost(){
		
		$field="water_price,commercial_electricity,gas_price,land_price,common_wages,social_insurance,people,industry_output";
		
		$condition=[];
		
	
		/***城市*/
		$city_id=request()->param('city_id',0,'intval');
		if(!empty($city_id)){
			$condition['city_id']=$city_id;
		}
		/***园区*/
		$park_id=request()->param('park_id',0,'intval');
		if(!empty($park_id)){
			$condition['park_id']=$park_id;
		}
		
		if(empty($condition)){
			if($this->role_id){
				$role=new Role();
				$RoleInfo=$role->detail($this->role_id);
				if(!empty($RoleInfo)){
					if(!empty($RoleInfo['park_id'])){
						$condition['park_id']=$RoleInfo['park_id'];
					}else{
						$condition['city_id']=$RoleInfo['city_id'];
					}
				}else{
					return json(['status'=>0,'msg'=>'平台不存在','data'=>[]]);
				}
			}else{
				return json(['status'=>0,'msg'=>'参数错误','data'=>[]]);
			}
		}
		//p($condition);
		$ResourceInvestCostModel=new ResourceInvestCostModel();
		$info=$ResourceInvestCostModel->GetDetail($field,$condition);
		
		return json(['status'=>1,'msg'=>'获取成功','data'=>$info]);
	}
	public function GetMap(){
		
		$field="chain_map,traffic_map,plan_map";
		
		$condition=[];
		
		
		/***城市*/
		$city_id=request()->param('city_id',0,'intval');
		if(!empty($city_id)){
			$condition['city_id']=$city_id;
		}
		/***园区*/
		$park_id=request()->param('park_id',0,'intval');
		if(!empty($park_id)){
			$condition['park_id']=$park_id;
		}
		
		if(empty($condition)){
			if($this->role_id){
				$role=new Role();
				$RoleInfo=$role->detail($this->role_id);
				if(!empty($RoleInfo)){
					if(!empty($RoleInfo['park_id'])){
						$condition['park_id']=$RoleInfo['park_id'];
					}else{
						$condition['city_id']=$RoleInfo['city_id'];
					}
				}else{
					return json(['status'=>0,'msg'=>'平台不存在','data'=>[]]);
				}
			}else{
				return json(['status'=>0,'msg'=>'参数错误','data'=>[]]);
			}
		}
		//p($condition);
		$ResourceMapModel=new ResourceMapModel();
		$info=$ResourceMapModel->GetDetail($field,$condition);
		
		return json(['status'=>1,'msg'=>'获取成功','data'=>$info]);
	}
	
	
}